import { getInfoByCode } from '@/api/code'
import { ref } from 'vue'

export default () => {
  const getInfoLoading = ref(false)

  const codeInfo = ref<CodeInfoByCode>({
    address: '',
    area: '',
    city: '',
    code: '',
    goodsBrand: '',
    goodsCode: '',
    goodsId: '',
    goodsModel: '',
    goodsName: '',
    goodsSpecId: '',
    goodsSpecName: '',
    goodsThreeType: '',
    goodsTwoType: '',
    goodsType: '',
    id: '',
    name: '',
    overInsured: false,
    phone: '',
    province: '',
    status: 1,
    town: '',
    userId: '',
    warrantyDay: 30,
    warrantyEndTime: '',
    warrantyStartTime: '',
  })

  const getInfo = async (code: string) => {
    getInfoLoading.value = true
    const res = await getInfoByCode(code)
    getInfoLoading.value = false
    codeInfo.value = res.data.data.row
  }

  return {
    codeInfo,
    getInfoLoading,
    getInfo,
  }
}
